package univer.oko.queryAnalizer;

import univer.oko.gui.CDInternalFrame;
import univer.oko.query.baseObjects.DBObject;

import javax.swing.*;
import java.awt.*;

/**
 * @author Eduard Dudar
 *         Date: 03.09.2005
 *         Time: 18:31:30
 */
public class QueryAnalyzer extends CDInternalFrame {
    private JPanel content;
    private JSplitPane splitPane;

    private TabContainer tabContainer;
    private QueryCompositePane queriesPane;

    public QueryCompositePane getQueriesPane() {
        return queriesPane;
    }

    public TabContainer getTabContainer() {
        return tabContainer;
    }

    public QueryAnalyzer() {

        this.content = (JPanel) this.getContentPane();
        this.content.setLayout(new BorderLayout());
        this.content.add(this.splitPane = new JSplitPane());
        this.splitPane.setLeftComponent(this.queriesPane = new QueryCompositePane(this));

        this.splitPane.setRightComponent(this.tabContainer = new TabContainer(this));
        this.splitPane.setDividerLocation(250);
        this.splitPane.setDividerSize(2);
        tabContainer.AddRefillTreeListener(queriesPane);
        this.setVisible(true);


    }

    public void prepareTab(DBObject ob, boolean isEditing, boolean isTextEditable) {
        if (!isEditing)//if new object
        {
            this.tabContainer.insertTab(ob, isEditing, isTextEditable, 0);
            this.tabContainer.setSelectedIndex(0);
        } else if (!this.tabContainer.isOpened(ob)) {
            this.tabContainer.insertTab(ob, isEditing, isTextEditable, 0);
            this.tabContainer.setSelectedIndex(0);
        } else {
            this.tabContainer.setSelectedDBObject(ob);
        }
    }

//	public void execute()
//	{
//		try
//		{
//			GeneratedData data = this.tabContainer.execute();
//			if (data != null)
//			{
//				HTMLReportWriter.createReport("Autogenerated Report",
//						data.getHeader(), data.getData(), new Vector(), new Vector(), new Vector(), true);
//			}
//		}
//		catch (RemoteException e)
//		{
//			e.printStackTrace();
//		}
//	}
}
